# -*- coding: UTF-8 -*-

from django.db import models
from accounts.models import User

class vmware_resource(models.Model):
    vm_cluster =models.CharField(max_length=255,null=True, verbose_name=u'虚拟化集群名称', unique=True)
    vm_sumcpu =models.CharField(max_length=255,null=True, verbose_name=u'总cpu核数')
    vm_leftcpu =models.CharField(max_length=255,null=True, verbose_name=u'剩余cpu核数')
    vm_summem =models.CharField(max_length=255,null=True, verbose_name=u'总内存容量')
    vm_leftmem =models.CharField(max_length=255,null=True, verbose_name=u'剩余内存容量')
    vm_sumdisk =models.CharField(max_length=255,null=True, verbose_name=u'总存储容量')
    vm_leftdisk =models.CharField(max_length=255,null=True, verbose_name=u'剩余存储容量')
    vm_hosts= models.IntegerField(null=True, verbose_name=u'虚拟机台数')

    def __unicode__(self):
        return self.vm_cluster

    class Meta:

        permissions = (
            ("view_vmcluster", ("查看集群")),
            ("add_vmcluster", ("增加集群")),
            ("edit_vmcluster", ("编辑集群")),
            ("del_vmcluster", ("删除集群")),
        )
        default_permissions = ()

class vmware_content(models.Model):
    vmware_system = (
        (0, u"win server2008r2"),
        (1, u"win server2012"),
        (2, u"win server2003"),
        (3, u"windows 7"),
        (4, u"windows xp"),
        (5, u"ubuntu 16.04"),
        (6, u"centos 6"),
        (7, u"centos 7"),
    )
    vmware_bit = (
        (0, u"32位"),
        (1, u"64位"),

    )
    vmware_cpu = (
        (0, u"2核"),
        (1, u"4核"),
        (2, u"8核"),
        (3, u"16核"),
        (4, u"32核"),

    )

    vmware_mem=(
        (0, u"2G"),
        (1, u"4G"),
        (2, u"8G"),
        (3, u"16G"),
        (4, u"32G"),

    )

    vmware_status= (
        (0, u"处理中"),
        (1, u"已处理"),
        (2, u"拒绝"),


    )

    vm_ip =models.CharField(max_length=255,null=True, verbose_name=u'ip', unique=True)
    vm_hostname = models.CharField(max_length=255, null=True,verbose_name=u'主机名')
    vm_ower = models.CharField(max_length=255, null=True,verbose_name=u'申请人')
    vm_system = models.IntegerField(choices=vmware_system,null=True, verbose_name=u'操作系统')
    vm_bit = models.IntegerField(choices=vmware_bit,null=True, verbose_name=u'操作系统位数')
    vm_cpu = models.IntegerField(choices=vmware_cpu,null=True, verbose_name=u'cpu')
    vm_mem = models.IntegerField(choices=vmware_mem,null=True, verbose_name=u'内存')
    vm_disk = models.CharField(max_length=255, null=True,verbose_name=u'磁盘')
    vm_use = models.CharField(max_length=255, null=True,verbose_name=u'用途')
    vm_status = models.IntegerField(choices=vmware_status,null=True, verbose_name=u'处理状态',default=0)
    vm_stime = models.DateField(verbose_name=u'开始使用时间',null=True)
    vm_endtime = models.DateField(verbose_name=u'回收时间',null=True)
    vm_beizhu =models.TextField(blank=True,null=True, verbose_name=u'备注')
    created_by = models.ForeignKey(User,blank=True, null=True, verbose_name=u'创建者')
    vm_cluster=models.ForeignKey(vmware_resource, on_delete=models.SET_NULL, null=True,
                                    verbose_name='归属集群', blank=True)

    def __unicode__(self):
        return self.vm_ower

    class Meta:

        permissions = (
            ("view_vm", ("查看申请列表")),
            ("add_vm", ("申请虚拟机")),
            ("edit_vm", ("编辑申请")),
            ("del_vm", ("删除申请")),
        )
        default_permissions = ()







